# List all the packages depending on packages modified on top of origin/master
new_or_updated_packages() {
    # arg1: git refspec start (default: origin/master)
    # arg2: git refspec stop (default: HEAD)
    git log "${1:-origin/master}..$2" --oneline |
        grep -E 'gnu: ([[:graph:]]+:|Add)' |
        sed -E 's/.*gnu: Add (.*).$/\1/' |
        sed -E 's/.*gnu: ([^:]*):.*/\1/' |
        sed -E 's/-([0-9.]*)$/@\1/' | sort | uniq
}

packages=$(new_or_updated_packages)

impacted_packages=$(./pre-inst-env guix refresh -l $packages |
                        sed 's/@\S*//g' | sed 's/^.*: //' | tr ' ' "\n" |
                        sort | uniq)

Example of result for git log --oneline origin/master..HEAD

$ git log --oneline origin/master..HEAD

e6281e7799 (HEAD -> master) gnu: python-psutil: Update to 5.8.0.
2aa1c322e4 gnu: python-geventhttpclient: Adjust to build with updated gevent.
da5422af1d gnu: python-greenlet: Update to 1.0.0.
f446f77d24 gnu: python-locust: Update to 1.4.3.
2268ae6fa9 doc: Add an example of how the open file descriptors limit can be raised.
aa36e7873f gnu: python-gevent: Update to 21.1.2.

Then running the above command yields:

$ echo $impacted_packages
s-tui bpytop thefuck clipper cwltool python-pytest-xprocess python-ccm
terminator python-pytest-openfiles python-transient
python-pytest-services python-sanic python-hyperkitty
python-mailman-hyperkitty python-hicexplorer python-pygenometracks
python-hic2cool synapse python-celery python-gridmap
python-scikit-image poetry pigx glances python-pysnptools
rapid-photo-downloader certbot ganeti unknown-horizons bpython
python-pynvim python-locust xandikos websockify python-swiftclient
python-ws4py eolie python-pykafka python-gipc python-pykka
gnome-shell-extension-gsconnect syncthing-gtk onionshare

# Use the above to find out which packages are currently building
broken_packages=$(guix weather --display-missing $impacted_packages |
                      awk '/\/gnu\/store/ \
{ print(gensub("[^-]*-(.*)-[0-9]+.*$", "\\1", 1, $1)) }' |
                      sed -E 's/(-[0-9.]*)*$//' | sort | uniq)

$ echo $broken_packages
s-tui
clipper
python-pytest-xprocess
python-ccm
python-pytest-openfiles
glances
python-pysnptools
python-hyperkitty
python-hicexplorer
python-hic2cool
python-scikit-image
python-pynvim
python-swiftclient
python-pykafka
python-pykka

# Which means the above impacted_packages are likely already broken on origin/master.

# Let's see if our changes improved/worsened the situation!
$ ./pre-inst-env guix build --keep-going $impacted_packages

[...]

# Alternatively, if the broken packages are costly to attempt building
# and not your current focus, you could omit rebuilding them with:
known_good_impacted_packages=$(echo $impacted_packages | tr ' ' "\n" | sort |
                                   comm -3 - <(echo $broken_packages |
                                                   tr ' ' "\n" | sort))

$ ./pre-inst-env guix build --keep-going $known_good_impacted_packages

# Let's lint
./pre-inst-env guix lint $packages
